﻿namespace eBdb.EpubReader.Collections
{
    using System;
    using System.Collections;
    using System.Collections.Generic;

    public class Hashtable : IDictionary
    {
        Dictionary<object, object> store;

        public Hashtable()
        {
            store = new Dictionary<object, object>();
        }

        public Hashtable(IDictionary d)
        {
            store = new Dictionary<object, object>();
            foreach (var key in d.Keys)
            {
                store.Add(key, d[key]);
            }
        }

        public Hashtable(IEqualityComparer equalityComparer)
        {
            store = new Dictionary<object, object>(equalityComparer as IEqualityComparer<object>);
        }

        public Hashtable(int capacity)
        {
            store = new Dictionary<object, object>(capacity);
        }

        public void Add(object key, object value)
        {
            store.Add(key, value);
        }

        public void Clear()
        {
            store.Clear();
        }

        public bool Contains(object key)
        {
            return store.ContainsKey(key);
        }

        public IDictionaryEnumerator GetEnumerator()
        {
            return store.GetEnumerator();
        }

        public bool IsFixedSize
        {
            get { return (store as IDictionary).IsFixedSize; }
        }

        public bool IsReadOnly
        {
            get { return (store as IDictionary).IsFixedSize; }
        }

        public ICollection Keys
        {
            get { return store.Keys; }
        }

        public void Remove(object key)
        {
            store.Remove(key);
        }

        public ICollection Values
        {
            get { return store.Values; }
        }

        public object this[object key]
        {
            get
            {
                return store[key];
            }
            set
            {
                store[key] = value;
            }
        }

        public void CopyTo(Array array, int index)
        {
            (store as ICollection).CopyTo(array, index);
        }

        public int Count
        {
            get { return store.Count; }
        }

        public bool IsSynchronized
        {
            get { return (store as ICollection).IsSynchronized; }
        }

        public object SyncRoot
        {
            get { return (store as ICollection).SyncRoot; }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return (store as IEnumerable).GetEnumerator();
        }
    }
}
